<?php
include '../../operations/connection.php';	
include 'substring-comment.php';
$id = $_REQUEST['idproject'];
$id_employee = $_REQUEST['idemp'];

$newlang = $_REQUEST['newlang'];
		
		if ($_REQUEST['newlang'] == "EN") {
			include "../../value/value_en.php";
		} else if($_REQUEST['newlang'] == "VN") {
			include "../../value/value_vn.php";
		}
		else {
			include "../../value/value_kr.php";
		}

$page = isset ( $_REQUEST["page"] ) ? intval ( $_REQUEST["page"] ) : 1;

$rows_per_page = 20;

$page_start = ( $page - 1 ) * $rows_per_page;
$page_end = $page * $rows_per_page; 

$queryListErrorByIDPr = mysql_query("SELECT tp.IDTest, tp.Title, tp.TextTest, tp.Time, tp.`Status`, tp.`Correct`,e.FullName,
				tp.IDTestTemp,pp.IDView,pp.NameProject,pc.backgroundColor,pc.backgroundConfirm,tp.Comment_Last,tp.NameEmployee_Last 
			   FROM pr_testproject tp, employee e ,pr_project pp,priority_color pc  WHERE pp.IDProject = tp.IDProject AND tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			    AND pc.id = tp.IdPriorityColor ORDER BY tp.`Status`=2 ASC,tp.DateConfirm DESC,tp.IdPriorityColor DESC,tp.Time DESC LIMIT $page_start,$rows_per_page ");

$re = mysql_query("SELECT tp.IDTest
			   		FROM pr_testproject tp, employee e WHERE tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			  		ORDER BY IDTest DESC");
$number_of_page = ceil ( mysql_num_rows( $re ) / $rows_per_page );
//keep list error
$_SESSION['projects'] = 'inlude_error.php' ;
?>
<a class="caption"><?php echo $l_list_error?> </a>
		<div class="divError divinvi" >
			<div class="rf-p divListError">
				<ul>	
					<li><a  class="linkAction" href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=1">
						<img src="images/list.png" alt="" />
						<span
							style="display: inline-block; width: 100%"><?php echo $l_error?>
						</span> </a></li>
					<li style="left: 150px"><a  class="linkAction" href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=2"><img
							src="images/recyclebin_empty.png" alt="" /><span
							style="display: inline-block; width: 100%"><?php echo $l_newfewture;?>
						</span> </a></li>
					
				</ul>
			</div>
			
			<div id='ajaxdelete' class="rf-p">
			<table width="100%" class="rf-dt" id="report">
			<?php 
			if (mysql_num_rows( $queryListErrorByIDPr )<=0) {
			?>
			<tr style="background: #f2f9ff" >
				<td colspan="5" style="padding: 10px"><?=$l_list_emplty?></td>
			</tr>
			<?php }else{
			$i = 0;
			while ($row=mysql_fetch_array($queryListErrorByIDPr)){
				$i++;
				$idtestproject = $row['IDTest'];
				$idemplTestpro = $row['IDEmployee'];
				$prdelete = $row['Delete'];
				$titletestpro = $row['Title'];
				$contenttestpro = $row['TextTest'];
				$fullnames = $row['FullName'];
				$time = $row['Time'];
				$indexcomment = (($page-1)*20)+$i;
				
				$stringcolortest = $row['Title'];
				if (strpos($stringcolortest,"-%$#@!-#")) {
					$stringcolortest =  substr($stringcolortest,0,strpos($stringcolortest,"-%$#@!-#"));
				}
				
				$idtesppr_temp = $row['IDTestTemp'];
				$idviewpro = $row['IDView'];
				$nampro = $row['NameProject'];
				
				$temp_mo = explode("-", $idtesppr_temp);
				$temp_mo_last = $temp_mo[0];
				$m="";
				if ($temp_mo_last==''){
					$m ="";
				}
				else if ($temp_mo_last==$nampro){
					$m = $idviewpro."-".$temp_mo[1];
				}else{
					$m = $idviewpro."-".$idtesppr_temp;
				}
				$stringcolor = substr($row['Comment_Last'],0,-14);
				//tag html tranh be giao dien
				
				$bgcolor = $row['backgroundColor'];
				$IdPriorityColor = $row['IdPriorityColor'];
				$errorstatus = $row['Status'];
				$namestatus = "";
				if ($errorstatus == 0){
					$namestatus = $l_no_fix;
				}else if ($errorstatus == 1){
					$namestatus = $l_fix_complete;
				}else if ($errorstatus == 2){
					$bgcolor = $row['backgroundConfirm'];
					$namestatus = $l_confirm_excel;
				}
				
				?>
				<tr style="background: <?php echo "#".$bgcolor;?>" >
					<td class="rf-dt-c"
						style="width: 8%; vertical-align: middle; text-align: center;min-width: 8%"><?php echo $m;?>
					</td>
					<td class="rf-dt-c"
						style="width: 9%; vertical-align: middle; text-align: center;min-width: 9%">
						<?php 
						if ($errorstatus == -1){
						?>
							<img src="images/newerror.png" alt="<?php echo $l_newerror?>" title="<?php echo $l_newerror?>"/> 
						<?php 
						}elseif ($errorstatus == 0){
						?>
							<img src="images/unconfirm.png" alt="<?php echo $l_no_fix?>" title="<?php echo $l_no_fix?>"/> 
						<?php 
						}elseif ($errorstatus == 1){
						?>
							<img src="images/fixed.png" alt="<?php echo $l_fix_complete?>" title="<?php echo $l_fix_complete?>"/> 
						<?php 
						}elseif ($errorstatus == 2){
						?>
							<img src="images/confirm.png" alt="<?php echo $l_confirm_excel?>" title="<?php echo $l_confirm_excel?>"/> 
						<?php 
						}
						?>
					</td>
					
					<td class="rf-dt-c" 
						style="padding: 7px; vertical-align: middle; width: 50%;">
						<div class="rowMinHeight" align="left" style="width: 97%;">
							<span onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" onclick="showcommanderror(<?=$indexcomment?>,'<?=$idtestproject?>','<?=$id_employee?>','<?=$id?>',0, this,'<?=$page?>');" class="titleError">
							 <a class="bclick" style="color: #424242;cursor:pointer;padding:2px;">
							<?php if(strlen($stringcolortest)==0){ echo  $titletestpro ;}else{echo  $stringcolortest;}?>
							 </a> </span>
							<div class="writeBy">
							
								<div align="right" style="width: 99%; float: left;">
								<span><?php include_once 'substring-comment.php';?>
								<?php 
								
								if (strlen($stringcolor)==0){
									$a=explode('<br>',$row['Comment_Last']);
									echo substringProvider::catchuoi($a[0],27);
								}else{
									$a=explode('<br>',$stringcolor);
									echo substringProvider::catchuoi($a[0],27);
								}
								
								?>
								</span> 
								<span style="font-weight: bold;"><?php  if ($row['NameEmployee_Last']!="") {
										echo '('.$row['NameEmployee_Last'].')';
										}?>
								</span>	
								</div>
							</div>
						</div>
					</td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 11%;">
						<?php echo $fullnames?></td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 9%;"><?php echo $time?>
					</td>
					
				</tr>
				
				<tr style="background: #f2f9ff; display:none" id="commentprojecthide" >
				</tr>
				
				<?php }}?>
				
				<tr class="trfoot">
                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="6">
                        	<div style="text-align: center; width: 100%">
				<?php 
				 
				 if ( $number_of_page > 1 ) { 
					 
				 	if($page!=1){?>
						<a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=1&page=<?=1?>">
					 		<span class="button_next" style="border:none"><?php echo "<<<<"?></span></a> 
					 	<a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=1&page=<?=($page-1)?>">
					 		<span onmouseover="" class="button_next" style="border:none"><?php echo "<<"?></span></a> 
					<?php  }
					else{
						echo "<span class='button_next' style='cursor:default'><<<</span>"; 
						echo "<span class='button_next' style='cursor:default'><<</span>";
					} 
					for ($i=1 ; $i<=$number_of_page ; $i++) {
						 if ($i == $page) {
				     	 	?><span class="button_next" style="border:none; cursor:default;"><b><?php echo $i;?></b></span><?php 
						}else {
				     		?><a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=1&page=<?=$i?>">
				     	 		<span class="button_next" style="border:none;color: #508e21;" ><b><?php echo $i;?></b></span></a> <?php 
				   		}
					}
				
					 if($page!=$number_of_page){ ?>
						<a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=1&page=<?=($page+1)?>">
					 		<span class="button_next" style="border:none"><?php echo ">>"?> </span></a>
					 	<a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$id?>&tab=1&page=<?=$number_of_page?>">
					 		<span class="button_next" style="border:none"><?php echo ">>>"?> </span></a><?php ;}
					else{
						echo "<span class='button_next' style='cursor:default'>>></span> ";
						echo "<span class='button_next' style='cursor:default'>>>></span> ";
					}
				}
				?>
				
				</div>
				</td>
				</tr>
			</table>
			</div>
		</div>
<?mysql_close($connection);?>